package cn.edu.xjtu.tencent.formal;

import java.util.ArrayList;

/**
 * @author Hydrion-QLz
 * @date 2022-09-13 20:39
 * @description
 */
public class second {
    public long solve(int k, ListNode a) {
        // write code here
        ArrayList<Integer> list = new ArrayList<>();
        while (a != null) {
            list.add(a.val);
            a = a.next;
        }
        long max = 0;
        for (int i = 0; i < list.size(); i++) {
            for (int j = i + 1; j < list.size(); j++) {
                max = Math.max(max, func(k, list.get(i), list.get(j)));
            }
        }
        return max;
    }

    public long func(int k, int x, int y) {
        return (long) (x ^ y) * k + ((long) x * y);
    }
}
